<template>
	<view class="empty-mod">
		<view class="empty-item" hover-class="hover-class" @click="netShow = true">
			<view class="item-icon">
				<u-icon name="plus"></u-icon>
			</view>
			<view class="item-lab">
				添加设备开启智能生活
			</view>
		</view>
		<u-action-sheet :list="netType" v-model="netShow" @click="netConfirm"></u-action-sheet>
	</view>
</template>

<script>
export default {
	components: {},
	data() {
		return {
			netShow:false,
			netType:[
				{
					text: 'NB通讯',
					id:1,
				},
				{
					text: 'WIFI配网',
					id:1,
				}
			], 
		};
	},
	props: {
		 
	},
	 
	computed: {},
	created() {
		 
	},
	methods: {
		jump(path) {
			this.$tools.routerTo(path);
		},
		netConfirm(index){
			if(index == 0){
				//打开二维码扫描
				this.scanCode();
			}
			else{
				// this.jump('/pages/device/add-device-step2')
				this.jump('/pages/device/bluetooth')
			}
		},
		scanCode(){
			let that = this;
			uni.scanCode({
				success: function (res) {
					if(res.scanType == 'QR_CODE'){
						let name = 'device_id';
						let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
						let param_url = res.result.substr(res.result.lastIndexOf('?')+1);
						let r = param_url.match(reg);
						if (r != null){
							console.log(r);
							let device_id = unescape(r[2]);
							that.$get("/api/member/nb_bind_equipment",{device_id:device_id}).then(ress => {
								if(ress.code == 1){
									uni.showModal({
										title:"系统提醒",
										content:'绑定成功',
										showCancel:false
									})
								}
							})
						}
					}
					else{
						uni.showModal({
							title:"系统提醒",
							content:'条码类型是：'+res.scanType+',暂时不支持此条码',
							showCancel:false
						})
					}
				}
			});
		},
	}
};
</script>

<style lang="scss" scoped>
	.empty-mod{
		padding:40upx 24upx;
	}
	.empty-item{
		padding: 70upx 40upx;
		text-align: center;
		font-size: 28upx;
		border-radius: 20upx;
		background-color: #fff;
		box-shadow: -1upx 2upx 20upx 0 rgba(6, 0, 1, 0.06);
		.item-icon{
			display: flex;
			justify-content: center;
			align-items: center;
			margin-left: auto;
			margin-right: auto;
			width: 116upx;
			height: 116upx;
			font-size: 44upx;
			color: #535353;
			background-color: #f5f5f5;
			border-radius: 100%;
		}
		.item-lab{
			margin-top: 32upx;
		}
		&.hover-class{
			color: #428cff;
			
			.item-icon{
				color: #428cff;
				background-color: rgb(232, 241, 255);
			}
		}
	}
</style>
